//#define NO_COLOR

#include <iostream>
#include <cstdint>

#ifndef NO_COLOR
#include <queue>
#endif

using namespace std;

constexpr const uintmax_t BLOCK_SIZE = 3;
constexpr const uintmax_t MAP_SIZE = BLOCK_SIZE*BLOCK_SIZE;

uintmax_t map[MAP_SIZE][MAP_SIZE] = {};

struct position{
    uintmax_t x;
    uintmax_t y;
    bool operator ==(position p){
        return x == p.x && y == p.y;
    }
};

#ifndef NO_COLOR
queue<position> empty_points;
#endif

bool isUnique(uintmax_t x, uintmax_t y, uintmax_t val){
    for(uintmax_t i = 0; i<MAP_SIZE; i++){
        if(map[x][i] == val && i != y){
            return false;
        }
    }
    for(uintmax_t i = 0; i<MAP_SIZE; i++){
        if(map[i][y] == val && i != x){
            return false;
        }
    }
    uintmax_t block_x = x/BLOCK_SIZE;
    uintmax_t block_y = y/BLOCK_SIZE;
    for(uintmax_t i = 0; i<BLOCK_SIZE; i++){
        for(uintmax_t j = 0; j<BLOCK_SIZE; j++){
            if(
                map[block_x*BLOCK_SIZE + i][block_y*BLOCK_SIZE + j] == val
                &&
                !(
                    block_x*BLOCK_SIZE + i == x
                    &&
                    block_y*BLOCK_SIZE + j == y
                )
            ){
                return false;
            }
        }
    }
    return true;
}

bool fill(){
    for(uintmax_t i = 0; i<MAP_SIZE; i++){
        for(uintmax_t j = 0; j<MAP_SIZE; j++){
            if(map[i][j] == 0){
                for(uintmax_t k = 1; k<=MAP_SIZE; k++){
                    if(isUnique(i, j, k)){
                        map[i][j] = k;
                        if(fill()){
                            return true;
                        }
                        map[i][j] = 0;
                    }
                }
                return false;
            }
        }
    }
    return true;
}

int main(){
    for(uintmax_t i = 0; i<MAP_SIZE; i++){
        for(uintmax_t j = 0; j<MAP_SIZE; j++){
            uintmax_t tmp;
            cin >> tmp;
            if(tmp<=MAP_SIZE){
                map[i][j] = tmp;
#ifndef NO_COLOR
                if(tmp == 0){
                    empty_points.push({i, j});
                }
#endif
            }else{
                cerr << "Invalid input" << endl;
                return 1;
            }
        }
    }
    if(!fill()){
        cerr << "No solution" << endl;
        return 1;
    }
    cout << "Solution:" << endl;
    for(uintmax_t i = 0; i<MAP_SIZE; i++){
        for(uintmax_t j = 0; j<MAP_SIZE; j++){
#ifndef NO_COLOR
            if(empty_points.front() == position{i, j}){
                cout << "\033[31m"
                     << map[i][j]
                     << "\033[0m ";
                empty_points.pop();
            }else
#endif
                cout << map[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}
